﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Skyworth.CRM.Common;
using Skyworth.CRM.Service.IBLL;

namespace Skyworth.CRM.Web.Orders
{
    public partial class OrderDetails : System.Web.UI.Page
    {
        protected int OrderId = 0;
        private static IOrdersBLL ordersBLL = IocContainer.Instance.Resolve<IOrdersBLL>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                int.TryParse(Request.QueryString["orderId"], out OrderId);
                DataTable dtDetail = ordersBLL.GetOrderDetail(OrderId);
                this.orderDetailBody.Text = BuildOrderDetail(dtDetail);
            }
        }

        protected string BuildOrderDetail(DataTable orderDetail)
        {
            StringBuilder result = new StringBuilder();
            if (orderDetail != null && orderDetail.Rows.Count > 0)
            {
                int i = 1;
                foreach (DataRow row in orderDetail.Rows)
                {
                    result.Append(i % 2 == 0 ? "<tr class='trbg'>" : "<tr>");
                    result.AppendFormat("<td>{0}</td>", row["FProductName"]);
                    result.AppendFormat("<td>{0}</td>", row["FUnitVolume"]);
                    result.AppendFormat("<td>{0}</td>", row["Fprice"]);
                    result.AppendFormat("<td>{0}</td>", row["Ftax"]);
                    result.AppendFormat("<td>{0}</td>", row["Ftaxprice"]);
                    result.AppendFormat("<td>{0}</td>", row["Ffanli"]);
                    result.AppendFormat("<td>{0}</td>", row["Fqty"]);
                    result.AppendFormat("<td>{0}</td>", row["Funit"]);
                    result.AppendFormat("<td>{0}</td>", row["Fqtyvolume"]);
                    result.AppendFormat("<td>{0}</td>", row["Famount"]);
                    result.AppendFormat("<td>{0}</td>", row["Ftaxamount"]);
                    result.AppendFormat("<td>{0}</td>", row["Fnote"]);
                    result.Append("</tr>");
                    i++;
                }
            }

            return result.ToString();
        }
    }
}
